import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/service_order_ddetail_data.dart';
import 'package:ls_work/res/resources.dart';
import 'package:ls_work/viewmodel/new_yyt_view_model.dart';
import 'package:ls_work/viewmodel/service_order/service_order_home_view_model.dart';
import 'package:ls_work/viewmodel/service_order/start_service_order_view_model.dart';
import 'package:ls_work/widgets/title_value_widget.dart';

class StartServiceOrderWidget extends BaseStatefulMvvmWidget {
  final ServiceOrderDdetailData detail;

  StartServiceOrderWidget(this.detail);

  @override
  State<StatefulWidget> createState() => _StartServiceOrderState();
}

class _StartServiceOrderState
    extends BaseMvvmState<StartServiceOrderViewModel, StartServiceOrderWidget> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        TitleValueWidget(
          '站点',
          isRequired: false,
          text: viewModel.siteName,
        ).onTap(() {
          viewModel.chooseSite();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '服务开始时间',
          isRequired: true,
          text: viewModel.startTime,
        ).onTap(() {
          viewModel.selectTime();
        }),

        Gaps.dividerLine,
        TitleValueWidget(
          '定位信息',
          isRequired: true,
          hint: '等待定位完成',
          text: viewModel.locationAddress,
          showArrow: false,
        ).onTap((){
          viewModel.showLocationRecord();
        }),
        Gaps.dividerLine,
        TitleValueWidget(
          '责任部门',
          text: NewYytViewModel.userInfo?.officeName??"",
          showArrow: false,
        ),
        Gaps.dividerLine,
        TitleValueWidget(
          '责任人',
          text: NewYytViewModel.userInfo?.name??"",
          showArrow: false,
        ),
        Gaps.dividerLine,
        Text.rich(TextSpan(
            text: "",
            style: TextStyle(color: Colors.red, fontSize: 16),
            children: [
              TextSpan(
                text: '上传照片',
                style: TextStyle(color: Colors.black, fontSize: 16),
              )
            ])).addToContainer(
            margin: EdgeInsets.only(left: 16, top: 16, bottom: 10)),
        viewModel.addImageWidget(),
        Container(height: 10,),
        Gaps.dividerLine,
        ElevatedButton(onPressed: (){
          viewModel.startClick();
        }, style: ButtonStyle(
          shape: WidgetStateProperty.all(StadiumBorder()),
          minimumSize: WidgetStateProperty.all(Size(double.infinity,40))
        ),child: CommonText('开始服务',textColor: Colors.white)).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16,vertical: 30))
      ],
    ).addToContainer(color: Colors.white);
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  StartServiceOrderViewModel createViewModel() {
    return StartServiceOrderViewModel(context,widget.detail);
  }

  @override
  void onRetryClick() {
  }
}
